﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Pages_FlightEdit : System.Web.UI.Page
{
	Int64 Entity_id { get { return DS.ToInt64(Request.QueryString["Id"]); } }

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			BindControls();
			if (Entity_id > 0)
				InitDataContext();
		}
	}

	protected void BindControls()
	{
		ddlBus.DataSource = DBEntity<Bus>.Select();
		ddlBus.DataBind();
		ddlRoute.DataSource = DBEntity<Route>.Select();
		ddlRoute.DataBind();
	}

	protected void InitDataContext()
	{
		TripRule f = DBEntity<TripRule>.Load(Entity_id);
		if (f == null)
			Response.Redirect("~/");
		ddlBus.SelectedValue = f.Bus_id.ToString();
		ddlRoute.SelectedValue = f.Route_id.ToString();
	}

	protected void OnFlightSave(object s, EventArgs e)
	{
		TripRule f = DBEntity<TripRule>.Load(Entity_id) ?? new TripRule();
		f.Bus_id = ddlBus.GetInt64Value();
		f.Route_id = ddlRoute.GetInt64Value();
		f.Merge();
	}

	protected void OnCancel(object s, EventArgs e)
	{
		Response.Redirect("~/Pages/Flight.aspx");
	}
}
